package com.example.servicepassengeruser.controller;

import com.example.internalcommon.dto.ResponseResult;
import com.example.internalcommon.request.VerificationCodeDTO;
import com.example.servicepassengeruser.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author lyra
 * @Date 2023/4/4 16:31
 **/
@RestController
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * 4.登录或注册
     *
     * @param verificationCodeDTO
     * @return
     */
    @PostMapping("/user")
    public ResponseResult loginOrRegister(@RequestBody VerificationCodeDTO verificationCodeDTO) {
        String passengerPhone = verificationCodeDTO.getPassengerPhone();
        System.out.println("手机号" + passengerPhone);
        return userService.loginOrRegister(passengerPhone);
    }

    /**
     * 10.通过手机号获取用户信息
     *
     * @param passengerPhone
     * @return
     */
    @GetMapping("/user/{phone}")
    public ResponseResult getUser(@PathVariable("phone") String passengerPhone) {
        System.out.println("service-passenger-user:phone" + passengerPhone);
        return userService.getUserByPhone(passengerPhone);
    }

}
